﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AGMLite.ViewModelClass;
using System.ComponentModel;
using HPAGMRestAPIWrapper;
using AGMLite.BaseClass;
using System.Data;

namespace AGMLite.Windows
{
    /// <summary>
    /// Interaction logic for ItemEditWindow.xaml
    /// </summary>
    public partial class ItemEditWindow : Window
    {
        public ItemEditWindow()
        {
            InitializeComponent();
            cmbEntityType.ItemsSource = Enum.GetValues(typeof(Common.AGMLiteEnum.EntityType));
            cmbOperation.ItemsSource = Enum.GetValues(typeof(Common.AGMLiteEnum.Operation));
        }

        private void cmbEntityType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ItemViewModel ivm = (ItemViewModel)this.DataContext;

            ivm.OnEntityTypeChanged((Common.AGMLiteEnum.EntityType)cmbEntityType.SelectedValue);
        }
    }

    public class FieldValueTemplateSelector : DataTemplateSelector
    {

        public DataTemplate ComboBoxTemplate

        { get; set; }


        public DataTemplate TextBoxTemplate

        { get; set; }


        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            AGMLiteEntityFilterField filterfield = item as AGMLiteEntityFilterField;

            if (filterfield != null)
            {
                if (filterfield.Field != null)
                {
                    if (filterfield.Field.Options == null)
                        return TextBoxTemplate;
                    else if (filterfield.Field.Options.Count > 0)
                        return ComboBoxTemplate;
                    else
                        return TextBoxTemplate;
                }
                else
                    return base.SelectTemplate(item, container);
            }
            else
                return base.SelectTemplate(item, container);
        }

    }
}
